﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Register : System.Web.UI.Page
{
    Bank.User _userregister;
    Bank.Balance _balance;
   
    protected void Page_Load(object sender, EventArgs e)
    {
        int userid = -1;
        try
        {
            userid = Convert.ToInt32(Session["userid"]);
        }
        catch (Exception)
        {
            userid = -1;
            Session["userid"] = -1;
        }
        if (userid > 0)
        {
            Response.Redirect("~/login.aspx");
        }
        _userregister = new Bank.User();
        _balance = new Bank.Balance();
        if (!Page.IsPostBack)
        {
          
            DataSet ds = _balance.getBanks();
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                ListItem item = new ListItem();
                item.Text = row[1].ToString();
                item.Value = row[0].ToString();
                DropDownList1.Items.Add(item);
            } 
        }
    }
 
    protected void Button1_Click(object sender, EventArgs e)
    {
        string username = TextBox1.Text;
        string email = TextBox4.Text;
        string warn = _userregister.check(username, email);
        if (warn.Length > 0)
        {
            MultiView1.ActiveViewIndex = 0;
            lblWarn.Text = warn;
        }
        else
        {
            lblWarn.Text = "";
            Session["pass"] = TextBox3.Text;
            MultiView1.ActiveViewIndex = 1;
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex = 0;
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex = 2;
        
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex = 1;

    }
    protected void Button5_Click(object sender, EventArgs e)
    {
        try
        {
            int id = _userregister.register(TextBox1.Text, Session["pass"].ToString(), TextBox4.Text, Convert.ToInt32(DropDownList1.SelectedValue), TextBox5.Text, TextBox6.Text, TextBox7.Text, Convert.ToInt64(TextBox8.Text));
            if (id > 0)
            {
                MultiView1.ActiveViewIndex = 3;
            }
            Session.Remove("pass");
        }
        catch (Exception)
        {

            throw;
        }
    }
}
